package bar.dark.lee.manager.card;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;

import bar.dark.lee.BDConstents;
import bar.dark.lee.R;
import bar.dark.lee.SuperActivity;
import bar.dark.lee.common.BDTextWatcher;
import bar.dark.lee.common.BDUtil;
import bar.dark.lee.common.DBSQLite;
import bar.dark.lee.common.EditTextInputFilter;
import bar.dark.lee.common.RadioDialogActivity;
import bar.dark.lee.common.DBSQLite.ParseSelectData;
import bar.dark.lee.manager.money.BankbookData;
import bar.dark.lee.widget.WidgetGetSqlQuery;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;

public class CreditCardUpdateActivity extends SuperActivity
{
	public static final String PREMONTH = "이전달 "; 
	public static final String NOWMONTH = "이번달 "; 
	public static final String NEXTMONTH = "다음달 ";
	public static final String DAY = "일";
	
	public static final int REQUEST_BANKBOOK = 0;
	public static final int REQUEST_END_DATE = 1;
	public static final int REQUEST_RESULT_DATE = 2;

	private DBSQLite sql;
	
	private EditText name;
	private EditText outmoney;
	private TextView monthMoney;
	private View linkView;
	private TextView linkTextView;
	
	private RadioButton radioNo;
	private RadioButton radioOk;
	
	private View dateView;
	private TextView startDateTextView;
	private TextView endDateTextView;
	private View resultDateView;
	private TextView resultDateTextView;
	
	private Button deleteButton;
	private Button updateButton;
	
	private CreditCardData data;
	
	private ArrayList<String> dateList = new ArrayList<String>();
	private CreditCardResultDateData creditResultData = null;
	
	private ArrayList<String> bankList;

	private int resultFlag = 1;
	
	private EditText orderEditText;
	
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		
		sql = DBSQLite.getInstance(this);
		
		setTitle("신용카드 수정");
		setGoneTipButton();
		
		setContentView(R.layout.manager_creditcard_update_activity);
		
		setFindView();
		setClickListener();
		new ShowDialog().execute(2);
	}

	private void setFindView()
	{
		name = (EditText) findViewById(R.id.creditCardUpdateName);
		
		outmoney = (EditText) findViewById(R.id.creditCardUpdateOutMoney);
		EditTextInputFilter.filteringMoneyEditText(outmoney);
		monthMoney = (TextView) findViewById(R.id.creditCardUpdateMonthMoney);
		
		linkView = findViewById(R.id.creditCardUpdateLinkType);
		linkTextView = (TextView) findViewById(R.id.creditCardUpdateLinkTypeTextView);
		deleteButton = (Button) findViewById(R.id.creditCardDeleteButton);
		updateButton = (Button) findViewById(R.id.creditCardUpdateButton);
		
		radioNo = (RadioButton) findViewById(R.id.creditUpdateRadioNo);
		radioOk = (RadioButton) findViewById(R.id.creditUpdateRadioOk);
		
		dateView = findViewById(R.id.creditUpdateDateView);
		startDateTextView = (TextView)findViewById(R.id.creditUpdateStartDateTextView);
		endDateTextView = (TextView)findViewById(R.id.creditUpdateEndDateTextView);
		resultDateView = findViewById(R.id.creditUpdateResultDateView);
		resultDateTextView = (TextView)findViewById(R.id.creditUpdateResultDateTextView);
		
		orderEditText = (EditText) findViewById(R.id.creditcardUpdateOrder);
	}

	private void setData()
	{
		for (int i = 0; i < 31; i++)
		{
			dateList.add((i+1) + "");
		}
		
		Intent intent = getIntent();
		data = intent.getParcelableExtra(CreditCardActivity.CREDITCARD_DATA);
		
		sql.selectMapTile(this, "SELECT * FROM credit_card_result_date WHERE linkid = "
				+ data.getId() + ";", new ParseSelectData()
		{
			@Override
			public void resultData(Cursor c)
			{
				int idIdx = c.getColumnIndex("id");
				int nameIdx = c.getColumnIndex("name");
				int autoynIdx = c.getColumnIndex("autoyn");
				int startdateIdx = c.getColumnIndex("startdate");
				int enddateIdx = c.getColumnIndex("enddate");
				int resultdateIdx = c.getColumnIndex("resultdate");
				int resultflagIdx = c.getColumnIndex("resultflag");
				int linkidIdx = c.getColumnIndex("linkid");
				
				c.moveToFirst();
				
				for (int i = 0; i < c.getCount(); i++)
				{
					creditResultData = new CreditCardResultDateData();
					
					creditResultData.setId(c.getInt(idIdx) + "");
					creditResultData.setName(c.getString(nameIdx));
					creditResultData.setAutoyn(c.getInt(autoynIdx) + "");
					creditResultData.setStartdate(c.getInt(startdateIdx) + "");
					creditResultData.setEnddate(c.getInt(enddateIdx) + "");
					creditResultData.setResultdate(c.getInt(resultdateIdx) + "");
					creditResultData.setResultflag(c.getInt(resultflagIdx) + "");
					creditResultData.setLinkid(c.getInt(linkidIdx) + "");
					
					c.moveToNext();
				}
			}
		});
		
		sql.selectMapTile(this, "SELECT name FROM bankbook;", new ParseSelectData()
		{
			@Override
			public void resultData(Cursor c)
			{
				bankList = new ArrayList<String>();
				
				int nameIndex = c.getColumnIndex("name");
				c.moveToFirst();
				
				for (int i = 0; i < c.getCount(); i++)
				{
					String name = c.getString(nameIndex);
					bankList.add(name);
					c.moveToNext();
				}
				
				if (bankList.size() < 1)
				{
					String name = "없음";
					bankList.add(name);
					linkView.setClickable(false);
					linkView.setTag(false);
				}
				else
				{
					linkView.setClickable(true);
					linkView.setTag(true);
				}
			}
		});
		
		sql.selectMapTile(this, "SELECT * FROM credit_card WHERE id = " + data.getId() + ";", 
				new ParseSelectData()
		{
			@Override
			public void resultData(Cursor c)
			{
				int count = c.getCount();
				c.moveToFirst();
				
				int outmoneyIndex = c.getColumnIndex("outmoney");
				
				for (int i = 0; i < count; i++)
				{
					data.setMaxMoney(c.getString(outmoneyIndex));
					
					c.moveToNext();
				}
			}
		});
	}

	private void setClickListener()
	{
		linkView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				Intent intent = new Intent(CreditCardUpdateActivity.this, RadioDialogActivity.class);
				intent.putExtra(RadioDialogActivity.RADIODATA, bankList);
				intent.putExtra(RadioDialogActivity.RADIOSELECT, linkTextView.getText().toString());
				startActivityForResult(intent, REQUEST_BANKBOOK);
			}
		});

		dateView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				Intent intent = new Intent(CreditCardUpdateActivity.this, RadioDialogActivity.class);
				intent.putExtra(RadioDialogActivity.RADIODATA, dateList);
				
				String selectData = getEndDate();
				
				intent.putExtra(RadioDialogActivity.RADIOSELECT, selectData);
				
				startActivityForResult(intent, REQUEST_END_DATE);
			}
		});
		
		resultDateView.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				Intent intent = new Intent(CreditCardUpdateActivity.this, RadioDialogActivity.class);
				intent.putExtra(RadioDialogActivity.RADIODATA, dateList);
				
				String selectData = getResultDate();
				
				intent.putExtra(RadioDialogActivity.RADIOSELECT, selectData);
				
				startActivityForResult(intent, REQUEST_RESULT_DATE);
			}
		});
		
		deleteButton.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				AlertDialog.Builder dialog = new AlertDialog.Builder(CreditCardUpdateActivity.this);
				
				dialog.setTitle("알림");
				dialog.setMessage("신용카드를 삭제 하시겠습니까? 신용카드가 삭제 될 경우 연결된 내역은 수정 삭제가 불가능합니다.");
				dialog.setPositiveButton("삭제", new DialogInterface.OnClickListener()
				{
					@Override
					public void onClick(DialogInterface dialog, int which)
					{
						new ShowDialog().execute(0);
						dialog.dismiss();
					}
				});
				
				dialog.setNegativeButton("취소", new DialogInterface.OnClickListener()
				{
					@Override
					public void onClick(DialogInterface dialog, int which)
					{
						dialog.dismiss();
					}
				});
				
				dialog.show();
			}
		});
		
		updateButton.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				setCreditCardUpdate();
			}
		});
	}
	
	private void setCreditDelete()
	{
		// 체크카드 연결된 내역들을 수정이나 삭제 못하게 막는다.
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("deleteyn", "1");
		String [] whereArgs1 = new String[]{
				BDConstents.CREDIT_TYPE, data.getName()};
		
		sql.update(this, 
				"in_out", map, "type = ? and moneykind = ?", whereArgs1);
		
		sql.update(this, 
				"in_out", map, "linktype = ? and moneykind = ?", whereArgs1);
		
		String [] whereArgs = new String[]{data.getId() + ""};
		sql.delete(CreditCardUpdateActivity.this, "credit_card", "id = ?", whereArgs);
		
		// 통장 자동화 테이블도 같이 삭제됩니다.
		sql.selectMapTile(this, "SELECT id FROM auto_bank WHERE moneykind = '"
				+ BDUtil.getApostrophe(data.getName()) + "' and kind = 2;", new ParseSelectData()
		{
			@Override
			public void resultData(Cursor c)
			{
				ArrayList<String> ids = new ArrayList<String>();
				
				int idIdx = c.getColumnIndex("id");
				
				c.moveToFirst();
				
				for (int i = 0; i < c.getCount(); i++)
				{
					ids.add(c.getInt(idIdx) + "");
					c.moveToNext();
				}
				
				for (int j = 0; j < ids.size(); j++)
				{
					String id = ids.get(j);
					
					String [] whereArgs = new String[]{id};
					sql.delete(CreditCardUpdateActivity.this, "auto_bank", "id = ?", whereArgs);
					
					// 할부 테이블도 같이 삭제 됩니다.
					sql.delete(CreditCardUpdateActivity.this, "auto_credit_date", "linkid = ?", whereArgs);
				}
			}
		});
		
		// 내통장 이체 자동화 테이블도 같이 삭제됩니다.
		sql.selectMapTile(this, "SELECT id FROM auto_mybank WHERE outkind = '"
				+ BDUtil.getApostrophe(data.getName()) + "' and kind = 2;", new ParseSelectData()
		{
			@Override
			public void resultData(Cursor c)
			{
				ArrayList<String> ids = new ArrayList<String>();
				
				int idIdx = c.getColumnIndex("id");
				
				c.moveToFirst();
				
				for (int i = 0; i < c.getCount(); i++)
				{
					ids.add(c.getInt(idIdx) + "");
					c.moveToNext();
				}
				
				for (int j = 0; j < ids.size(); j++)
				{
					String id = ids.get(j);
					
					String [] whereArgs = new String[]{id};
					sql.delete(CreditCardUpdateActivity.this, "auto_mybank", "id = ?", whereArgs);
				}
			}
		});
		
		// 결제일 자동이체 테이블 삭제
		String [] where = new String[]{data.getId()};
		sql.delete(this, "credit_card_result_date", "linkid = ?", where);
		
		// 세부신용카드 테이블에서도 삭제한다
		String [] whereArgs2 = new String[]{data.getId()};
		sql.delete(this, "creditcard_detail", "linkid = ?", whereArgs2);
		
		// 자산이 삭제 되면 메인 화면 셋팅 값도 삭제 시킨다.
		WidgetGetSqlQuery widgetQuery = new WidgetGetSqlQuery(superContext);
		widgetQuery.setManagerDelete(data.getName(), WidgetGetSqlQuery.CREDITCARD);
	}
	
	/**
	 * 신용카드를 수정한다.
	 */
	private void setCreditCardUpdate()
	{
		if (name.getText().toString().trim().equals(""))
		{
			BDUtil.showDialog(this, "확인", "카드이름을 입력해주세요.");
			return;
		}
		
		if (BDUtil.getCommaDel(outmoney.getText().toString()).trim().equals(""))
		{
			BDUtil.showDialog(this, "확인", "결제예정금액을 입력해주세요.");
			return;
		}
		
		boolean nameOverlap = false;
		
		if (!data.getName().equals(name.getText().toString()))
		{
			nameOverlap = BDUtil.getOverlapCheck(sql, superContext, 
					"SELECT name FROM credit_card WHERE name = '" + BDUtil.getApostrophe(name.getText().toString()) + "';");
		}
		
		if (nameOverlap)
		{
			BDUtil.showDialog(CreditCardUpdateActivity.this, "경고", "동일한 카드 이름이 존재 합니다");
			name.setText(data.getName());
			return;
		}
		
		if ((Boolean) linkView.getTag() == false)
		{
			BDUtil.showDialog(superContext, "알림", "통장이 하나도 없습니다. 통장부터 만들어주세요.");
			return;
		}
		
		if (orderEditText.getText().equals("") || orderEditText.getText().length() < 1
				|| Integer.parseInt(orderEditText.getText().toString()) < 1 || Integer.parseInt(orderEditText.getText().toString()) > 999 )
		{
			BDUtil.showDialog(superContext, "확인", "표시순위를 제대로 입력해주세요.(1~999)");
			return;
		}
		
		new ShowDialog().execute(1);
	}

	private void setCreditCardUpdateData()
	{
		sql.selectMapTile(this, "SELECT id FROM bankbook WHERE name = '"
				+ BDUtil.getApostrophe(linkTextView.getText().toString()) + "';", new ParseSelectData()
		{
			@Override
			public void resultData(Cursor c)
			{
				int idIdx = c.getColumnIndex("id");
				
				c.moveToFirst();
				int id = -1;
				
				for (int i = 0; i < c.getCount(); i++)
				{
					id = c.getInt(idIdx);
					c.moveToNext();
				}
				
				if (id > -1)
				{
					HashMap<String, String> map = new HashMap<String, String>();
					map.put("banklink", id + "");
					map.put("name", name.getText().toString());
					map.put("outmoney", BDUtil.getCommaDel(outmoney.getText().toString()));
					String [] whereArgs = new String[]{data.getId() + ""};
					sql.update(CreditCardUpdateActivity.this, "credit_card", map, "id = ?", whereArgs);
				}
			}
		});
		
		// 통장 자동화 테이블도 같이 수정됩니다.
		sql.selectMapTile(this, "SELECT id FROM auto_bank WHERE moneykind = '"
				+ BDUtil.getApostrophe(data.getName()) + "' and kind = 2;", new ParseSelectData()
		{
			@Override
			public void resultData(Cursor c)
			{
				ArrayList<String> ids = new ArrayList<String>();
				
				int idIdx = c.getColumnIndex("id");
				
				c.moveToFirst();
				
				for (int i = 0; i < c.getCount(); i++)
				{
					ids.add(c.getInt(idIdx) + "");
					c.moveToNext();
				}
				
				for (int j = 0; j < ids.size(); j++)
				{
					String id = ids.get(j);
					
					HashMap<String, String> map = new HashMap<String, String>();
					map.put("moneykind", name.getText().toString());
					
					String [] whereArgs = new String[]{id};
					sql.update(CreditCardUpdateActivity.this, "auto_bank", map, "id = ?", whereArgs);
					
					// 할부 테이블도 전부 수정.
					HashMap<String, String> map2 = new HashMap<String, String>();
					map2.put("name", name.getText().toString());
					sql.update(CreditCardUpdateActivity.this, "auto_credit_date", map2, "linkid = ?", whereArgs);
				}
			}
		});
		
		// 내통장 이체 자동화 테이블도 같이 수정됩니다.
		sql.selectMapTile(this, "SELECT id FROM auto_mybank WHERE outkind = '"
				+ BDUtil.getApostrophe(data.getName()) + "' and kind = 2;", new ParseSelectData()
		{
			@Override
			public void resultData(Cursor c)
			{
				ArrayList<String> ids = new ArrayList<String>();
				
				int idIdx = c.getColumnIndex("id");
				
				c.moveToFirst();
				
				for (int i = 0; i < c.getCount(); i++)
				{
					ids.add(c.getInt(idIdx) + "");
					c.moveToNext();
				}
				
				for (int j = 0; j < ids.size(); j++)
				{
					String id = ids.get(j);
					
					HashMap<String, String> map = new HashMap<String, String>();
					map.put("outkind", name.getText().toString());
					
					String [] whereArgs = new String[]{id};
					sql.update(CreditCardUpdateActivity.this, "auto_mybank", map, "id = ?", whereArgs);
				}
			}
		});
		
		setCreditDateUpdateData();
		
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("name", name.getText().toString());
		map.put("count", orderEditText.getText().toString());
		
		String [] whereArgs2 = new String[]{data.getId()};
		
		// 세부 통장 테이블에 데이터를 수정한다.
		sql.update(superContext, "creditcard_detail", map, "linkid = ?", whereArgs2);
		
		// 자산이 삭제 되면 메인 화면 셋팅 값도 수정 시킨다.
		WidgetGetSqlQuery widgetQuery = new WidgetGetSqlQuery(superContext);
		widgetQuery.setManagerUpdate(data.getName(), name.getText().toString(), WidgetGetSqlQuery.CREDITCARD);
	}
	
	private void setCreditDateUpdateData()
	{
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("name", name.getText().toString().trim());
		map.put("linkname", linkTextView.getText().toString());
		
		if (radioNo.isChecked())
		{
			map.put("autoyn", "2");
		}
		else
		{
			map.put("autoyn", "1");
		}
		
		map.put("startdate", getStartDate());
		map.put("enddate", getEndDate());
		map.put("resultdate", getResultDate());
		
		Calendar cal = Calendar.getInstance();
		
		int year = cal.get(Calendar.YEAR);
		int month = cal.get(Calendar.MONTH)+1;
		int day = Integer.parseInt(getResultDate());
		
		if (day >= cal.get(Calendar.DAY_OF_MONTH))
		{
			if (month == 1)
			{
				year--;
				month = 12;
			}
			else 
			{
				month--;
			}
		}
		
		map.put("signdate", BDUtil.getDateDB(year, month, day));
		
		if (resultFlag == 1)
		{
			map.put("resultflag", "1");
		}
		else
		{
			map.put("resultflag", "2");
		}
		
		String [] whereArgs = new String[]{data.getId()};
		
		if (creditResultData != null)
		{
			sql.update(this, "credit_card_result_date", map, "linkid = ?", whereArgs);
		}
		else
		{
			map.put("linkid", data.getId());
			sql.insert(this, map, "credit_card_result_date");
		}
	}
	
	private String getStartDate()
	{
		try
		{
			String selectData = startDateTextView.getText().toString().replace(NOWMONTH, "");
			selectData = selectData.replace(PREMONTH, "");
			selectData = selectData.replace(DAY, "");
			
			return selectData;
		} catch (Exception e)
		{
			return startDateTextView.getText().toString();
		}
	}

	private String getEndDate()
	{
		try
		{
			String selectData = endDateTextView.getText().toString().replace(NOWMONTH, "");
			selectData = selectData.replace(DAY, "");
			
			return selectData;
		} catch (Exception e)
		{
			return endDateTextView.getText().toString();
		}
	}
	
	private String getResultDate()
	{
		try
		{
			String selectData = resultDateTextView.getText().toString().replace(NOWMONTH, "");
			selectData = selectData.replace(NEXTMONTH, "");
			selectData = selectData.replace(DAY, "");
			
			return selectData;
		} catch (Exception e)
		{
			return resultDateTextView.getText().toString();
		}
	}
	
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data)
	{
		super.onActivityResult(requestCode, resultCode, data);
		
		if (resultCode == Activity.RESULT_OK)
		{
			if (requestCode == REQUEST_END_DATE)
			{
				String selectData = data.getStringExtra(RadioDialogActivity.RADIOSTRING);
				
				int endDate = Integer.parseInt(selectData);
				int resultDate = Integer.parseInt(getResultDate());
				int startDate = Integer.parseInt(selectData)+1;
				
				if (resultDate > endDate)
				{
					resultFlag =1;
					resultDateTextView.setText(NOWMONTH + resultDate + DAY);
				}
				else if (resultDate < endDate)
				{
					resultFlag = 2;
					resultDateTextView.setText(NEXTMONTH + resultDate + DAY);
				}
				else if (resultDate == endDate)
				{
					BDUtil.showDialog(this, "경고", "적용 마지막 날짜와 결제일은 같은 날을 할수 없습니다.");
					return;
				}
				
				endDateTextView.setText(NOWMONTH + selectData + DAY);
				
				if (endDate == 31)
				{
					startDate = 1;
					startDateTextView.setText(NOWMONTH + startDate + DAY);
				}
				else
				{
					startDateTextView.setText(PREMONTH + startDate + DAY);
				}
			}
			else if (requestCode == REQUEST_RESULT_DATE)
			{
				String selectData = data.getStringExtra(RadioDialogActivity.RADIOSTRING);
				
				int endDate = Integer.parseInt(getEndDate());
				int resultDate = Integer.parseInt(selectData);
				
				if (resultDate > endDate)
				{
					resultFlag =1;
					resultDateTextView.setText(NOWMONTH + selectData + DAY);
				}
				else if (resultDate < endDate)
				{
					resultFlag = 2;
					resultDateTextView.setText(NEXTMONTH + selectData + DAY);
				}
				else if (resultDate == endDate)
				{
					BDUtil.showDialog(this, "경고", "적용 마지막 날짜와 결제일은 같은 날을 할수 없습니다.");
				}
				
			}
			else if (requestCode == REQUEST_BANKBOOK)
			{
				if (resultCode == Activity.RESULT_OK)
				{
					String selectData = data.getStringExtra(RadioDialogActivity.RADIOSTRING);
					linkTextView.setText(selectData);
				}
			}
		}
	}
	
	/**
	 * 다이얼로그 뛰우기 
	 */
	private class ShowDialog extends AsyncTask<Integer, Integer, Integer>{
		ProgressDialog dialog = null;
		
		@Override
		protected void onPreExecute() {
			super.onPreExecute();
			dialog = new ProgressDialog(CreditCardUpdateActivity.this);
			dialog.setCancelable(false);
			dialog.setMessage("Loading...");
			dialog.show();
		}
		
		@Override
		protected Integer doInBackground(Integer... arg0) {
			
			if (arg0[0] == 0)
			{
				try
				{
					sql.beginTansaction(superContext);
					
					setCreditDelete();
					
					sql.setTransactionSuccessful();
				} catch (Exception e)
				{
					return -1;
				} finally {
					try 
					{
						sql.endTransaction(superContext);
					} catch (Exception e) 
					{
						return -1;
					}
				}
				return 0;
			}
			else if (arg0[0] == 1)
			{
				try
				{
					sql.beginTansaction(superContext);
					
					setCreditCardUpdateData();
					
					sql.setTransactionSuccessful();
				} catch (Exception e)
				{
					return -1;
				} finally {
					try 
					{
						sql.endTransaction(superContext);
					} catch (Exception e) 
					{
						return -1;
					}
				}
				return 1;
			}
			else if (arg0[0] == 2)
			{
				setData();
				return 2;
			}
			
			return null;
		}

		@Override
		protected void onPostExecute(Integer result) {
			super.onPostExecute(result);
			
			dialog.dismiss();
			
			if (result == -1)
			{
				BDUtil.btnEnable = true;
				BDUtil.asyncFlag = 0;
				
				BDUtil.showDialog(superContext, "오류", "데이터 저장에 실패했습니다.");
			}
			else if (result == 0)
			{
				BDUtil.showDialogFinish(CreditCardUpdateActivity.this, "삭제", "신용카드가 삭제 되었습니다.");
			}
			else if (result == 1)
			{
				BDUtil.showDialogFinish(CreditCardUpdateActivity.this, "수정", "신용카드가 수정 되었습니다.");
			}
			else if (result == 2)
			{
				name.setText(data.getName());
				outmoney.setText(data.getMaxMoney());
				monthMoney.setText(BDUtil.getWon(data.getOutMoney()) + shape);
				
				linkTextView.setText(data.getLinkName());
				
				if (data.getOrder().equals("0"))
				{
					orderEditText.setText("999");
				}
				else
				{
					orderEditText.setText(data.getOrder());
				}
				
				// 자동 결제일 데이터 셋팅 부분.
				if (creditResultData != null)
				{
					if (creditResultData.getAutoyn().equals("1"))
					{
						radioOk.setChecked(true);
						radioNo.setChecked(false);
					}
					else
					{
						radioOk.setChecked(false);
						radioNo.setChecked(true);
					}
					
					int endDate = Integer.parseInt(creditResultData.getEnddate());
					int resultDate = Integer.parseInt(creditResultData.getResultdate());
					int startDate = endDate+1;
					
					if (resultDate > endDate)
					{
						resultFlag =1;
						resultDateTextView.setText(NOWMONTH + resultDate + DAY);
					}
					else if (resultDate < endDate)
					{
						resultFlag = 2;
						resultDateTextView.setText(NEXTMONTH + resultDate + DAY);
					}
					
					endDateTextView.setText(NOWMONTH + endDate + DAY);
					
					if (endDate == 31)
					{
						startDate = 1;
						startDateTextView.setText(NOWMONTH + startDate + DAY);
					}
					else
					{
						startDateTextView.setText(PREMONTH + startDate + DAY);
					}
				}
				else
				{
					radioOk.setChecked(false);
					radioNo.setChecked(true);
					
					startDateTextView.setText(PREMONTH + dateList.get(1) + DAY);
					endDateTextView.setText(NOWMONTH + dateList.get(0) + DAY);
					resultDateTextView.setText(NOWMONTH + dateList.get(2) + DAY);
					resultFlag = 1;
				}
			}
		}
	}
	
	@Override
	protected void tipButton()
	{
	}
}
